package com.example.myapplication.found.model;

import com.example.myapplication.found.bean.StockBean;
import com.example.myapplication.found.bean.StockKlineBean;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: rongfeng
 * @date: 2022/8/9
 * @description 上涨前一天分析
 */
public class Fenxi5 extends BaseData {
    public Fenxi5(StockBean stockBean, StockBean weekStockBean) {
        super(stockBean, weekStockBean);
    }

    public static List<StockKlineBean> lastList = new ArrayList<>();
    static List<String> codeList = new ArrayList<>();

    @Override
    public void start() {
        if (!codeList.contains(fundCode)) {
            codeList.add(fundCode);
        } else {
            if (callback != null) {
                callback.fenxiCallback(1);
            }
            return;
        }
        for (int i = 0; i < stockBean.klineList.size(); i++) {
            StockKlineBean bean = stockBean.klineList.get(i);
            if (bean.chg > 2) {
                if (i - 1 >= 0) {
                    StockKlineBean lastBean = stockBean.klineList.get(i - 1);
                    lastList.add(lastBean);
                }
            }
        }
        callback.fenxiCallback(1);
    }


    public static int range0, range1, range2, range3, range4, range5, range6, range7, range8, range9, range10, range11;
    public static int _range1, _range2, _range3, _range4, _range5, _range6, _range7, _range8, _range9, _range10, _range11;

    public static void analysis() {
        double chgAvg = 0;
        int zhang = 0;
        int die = 0;
        double avg1 = 0;

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < lastList.size(); i++) {
            StockKlineBean stockKlineBean = lastList.get(i);
            chgAvg += stockKlineBean.chg;
            if (stockKlineBean.chg > 0) {
                zhang++;
            } else  if (stockKlineBean.chg < 0) {
                die++;
            }
            if (stockKlineBean.chg == 0) {
                range0++;
            } else if (stockKlineBean.chg > 0 && stockKlineBean.chg <= 1) {
                range1++;
            } else if (stockKlineBean.chg > 1 && stockKlineBean.chg <= 2) {
                range2++;
            } else if (stockKlineBean.chg > 2 && stockKlineBean.chg <= 3) {
                range3++;
            } else if (stockKlineBean.chg > 3 && stockKlineBean.chg <= 4) {
                range4++;
            } else if (stockKlineBean.chg > 4 && stockKlineBean.chg <= 5) {
                range5++;
            } else if (stockKlineBean.chg > 5 && stockKlineBean.chg <= 6) {
                range6++;
            } else if (stockKlineBean.chg > 6 && stockKlineBean.chg <= 7) {
                range7++;
            } else if (stockKlineBean.chg > 7 && stockKlineBean.chg <= 8) {
                range8++;
            } else if (stockKlineBean.chg > 8 && stockKlineBean.chg <= 9) {
                range9++;
            } else if (stockKlineBean.chg > 9 && stockKlineBean.chg <= 10) {
                range10++;
            } else if (stockKlineBean.chg > 10) {
                range11++;
            } else if (stockKlineBean.chg < 0 && stockKlineBean.chg > -1) {
                _range1++;
            } else if (stockKlineBean.chg < -1 && stockKlineBean.chg > -2) {
                _range2++;
            } else if (stockKlineBean.chg < -2 && stockKlineBean.chg > -3) {
                _range3++;
            } else if (stockKlineBean.chg < -3 && stockKlineBean.chg > -4) {
                _range4++;
            } else if (stockKlineBean.chg < -4 && stockKlineBean.chg > -5) {
                _range5++;
            } else if (stockKlineBean.chg < -5 && stockKlineBean.chg > -6) {
                _range6++;
            } else if (stockKlineBean.chg < -6 && stockKlineBean.chg > -7) {
                _range7++;
            } else if (stockKlineBean.chg < -7 && stockKlineBean.chg > -8) {
                _range8++;
            } else if (stockKlineBean.chg < -8 && stockKlineBean.chg > -9) {
                _range9++;
            } else if (stockKlineBean.chg < -9 && stockKlineBean.chg > -10) {
                _range10++;
            } else if (stockKlineBean.chg < -10) {
                _range11++;
            }
        }

        int lineTotal = lastList.size();

        System.out.println("0%：" + range0 + " " + ((float) range0 / lineTotal) * 100);
        System.out.println(">10%：" + range11 + " " + ((float) range11 / lineTotal) * 100);
        System.out.println("9%~10%：" + range10 + " " + ((float) range10 / lineTotal) * 100);
        System.out.println("8%~9%：" + range9 + " " + ((float) range9 / lineTotal) * 100);
        System.out.println("7%~8%：" + range8 + " " + ((float) range8 / lineTotal) * 100);
        System.out.println("6%~7%：" + range7 + " " + ((float) range7 / lineTotal) * 100);
        System.out.println("5%~6%：" + range6 + " " + ((float) range6 / lineTotal) * 100);
        System.out.println("4%~5%：" + range5 + " " + ((float) range5 / lineTotal) * 100);
        System.out.println("3%~4%：" + range4 + " " + ((float) range4 / lineTotal) * 100);
        System.out.println("2%~3%：" + range3 + " " + ((float) range3 / lineTotal) * 100);
        System.out.println("1%~2%：" + range2 + " " + ((float) range2 / lineTotal) * 100);
        System.out.println("0%~1%：" + range1 + " " + ((float) range1 / lineTotal) * 100);
        System.out.println();
        System.out.println("0%~-1%：" + _range1 + " " + ((float) _range1 / lineTotal) * 100);
        System.out.println("-1%~-2%：" + _range2 + " " + ((float) _range2 / lineTotal) * 100);
        System.out.println("-2%~-3%：" + _range3 + " " + ((float) _range3 / lineTotal) * 100);
        System.out.println("-3%~-4%：" + _range4 + " " + ((float) _range4 / lineTotal) * 100);
        System.out.println("-4%~-5%：" + _range5 + " " + ((float) _range5 / lineTotal) * 100);
        System.out.println("-5%~-6%：" + _range6 + " " + ((float) _range6 / lineTotal) * 100);
        System.out.println("-6%~-7%：" + _range7 + " " + ((float) _range7 / lineTotal) * 100);
        System.out.println("-7%~-8%：" + _range8 + " " + ((float) _range8 / lineTotal) * 100);
        System.out.println("-8%~-9%：" + _range9 + " " + ((float) _range9 / lineTotal) * 100);
        System.out.println("-9%~-10%：" + _range10 + " " + ((float) _range10 / lineTotal) * 100);
        System.out.println("<-10%：" + _range11 + " " + ((float) _range11 / lineTotal) * 100);


        System.out.println(stringBuilder);
        System.out.println("avg1 " + (avg1 / lineTotal));


        System.out.println("涨次数 " + zhang);
        System.out.println("跌次数 " + die);
        System.out.println("涨跌幅平局 " + (chgAvg / lastList.size()));
    }
}
